#include<bits/stdc++.h>
using namespace std;
int a[200010],b[2000010];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n,ans=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            b[a[i]]++;
        }
        for(int i=1;i<=n;i++){
            if(b[i]>=2){
                ans+=b[i];
            }
        }
        cout<<ans<<endl;
    }
}